<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/7/5 0005
 * Time: 14:12
 * 认证类
 */
namespace app\models;

use yii\db\ActiveRecord;
use yii\web\IdentityInterface;

class Admin  extends ActiveRecord implements IdentityInterface
{

    public function getUserName ($username) {
        $user = new Admin();
//        $user
    }
    
    


    /**
     * 验证cookie
     * @param string $authKey
     * @return bool
     */
    public function validateAuthKey($authKey)
    {
        // TODO: Implement validateAuthKey() method.
        return $this->getAuthKey() === $authKey;
    }

    /**
     * @return mixed int||string 用户的ID
     */
    public function getId()
    {
        // TODO: Implement getId() method.
        return $this->id;
    }

    /**
     * @return mixed  string 当前用户的cookie 密钥
     */
    public function getAuthKey()
    {
        // TODO: Implement getAuthKey() method.
        return $this->auth_key;
    }

    /**
     * 根据ID 查询用户身份
     * @param int|string $id
     * @return static 通过id匹配到的身份对象
     */
    public static function findIdentity($id)
    {
        // TODO: Implement findIdentity() method.
        return static::findOne($id);
    }


    /**
     * @param mixed $token          被查询的token
     * @param null $type
     * @return static object||null 根据token查询到的身份对象
     */
    public static function findIdentityByAccessToken($token, $type = null)
    {
        // TODO: Implement findIdentityByAccessToken() method.

        return static::findOne(['access_token'=>$token]);
    }
}